package com.clinic.controller;

import com.clinic.entity.Clinicpatient;
import com.clinic.service.ClinicpatientService;
import com.clinic.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Clinicpatient)表控制层
 *
 * @author makejava
 * @since 2020-11-12 15:55:16
 */

@RequestMapping(value = "/api")
@RestController
public class ClinicpatientController {
    /**
     * 服务对象
     */
    @Autowired
    private ClinicpatientService clinicpatientService;

    /**
     * 通过主键查询单条数据
     *
     * @return 单条数据
     */


    //查询所有患者信息
    @GetMapping("/selectAllPats")
    public ActionResult findAllPatients() {
    List<Clinicpatient> clinicpatients=clinicpatientService.findAllPatients();
    if (clinicpatients!=null || clinicpatients.size()>0) {
        return new ActionResult(200, "查询成功", clinicpatients);
    }
        return new ActionResult(500,"查询失败",null);
    }

    //修改患者信息

    @PostMapping("/updatePats")
    public ActionResult updatePatients(int pid){
        int count = clinicpatientService.updatePatients(pid);
        if (count!=0){
            return new ActionResult(200,"修改成功",count);
        }
            return new ActionResult(500,"修改失败",null);
    }
    //删除患者信息
    @DeleteMapping("/deletePatient")
    public ActionResult deletePatient(int pid){
        boolean count = clinicpatientService.deletePatient(pid);
        if(count){
            return new ActionResult(200,"删除成功",null);
        }
            return new ActionResult(500,"删除失败",null);
    }
    //添加患者数据
    @PostMapping("/addPats")
    public ActionResult addPatients(Clinicpatient clinicpatient){
        boolean patient = clinicpatientService.addPatient(clinicpatient);
        if (patient){
            return new ActionResult(200,"怎加成功",patient);
        }
            return new ActionResult(500,"增加失败",null);
    }
}